const path = require("path")
const htmlWebpackPlugin = require("html-webpack-plugin")
// __dirname 与porcess.cwd() 返回的路径都是命令行执行的路径
module.exports = {
    mode: 'development',
    devtool: 'inline-source-map',
    //devServer服务启动目录
    devServer: {
        static: './dist'
    },
    optimization: {
        runtimeChunk: 'single'
    },
    entry: {
        main: './main.js',
        print: './src/print.js',
    },//入口
    output: {
        filename: "[name].bundle.js", //打包后的文件名称 [name] 默认是main.js
        path: path.resolve(__dirname, "dist"), //打包后的文件路径
        clean: true,
        publicPath: "/"
    },
    plugins: [
        //如果要修改标题，index.html 中需要读取这个title <%= htmlWebpackPlugin.options.title %>
        new htmlWebpackPlugin({
            template: "./index.html",
            title: 'Development',
        }),
    ],
    module: {
        rules: [
            {
                //处理.css结尾文件的loader
                test: /\.css$/i,
                use: ["style-loader", "css-loader"]
            },
            {
                test: /\.(png|svg|jpg|jpeg|gif)$/i,
                type: "asset/resource"
            },
        ]
    }
}



